package com.lmx.repoDomain.tmodel;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.ForeignKey;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;
import io.katharsis.resource.annotations.JsonApiIncludeByDefault;
import io.katharsis.resource.annotations.JsonApiResource;
import io.katharsis.resource.annotations.JsonApiToOne;

/**
 * 城市表
 */
@JsonApiResource(type = "city")
@Table(name = "t_s_city")
@Entity
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class City extends BaseEntity {

	private String remark;// 备注

	private String name;

	private Province province;

	// private List<Room> rooms;
	// @Transient
	// @JsonApiToMany
	// @JsonApiIncludeByDefault
	// public List<Room> getRooms() {
	// return rooms;
	// }
	//
	// public void setRooms(List<Room> rooms) {
	// this.rooms = rooms;
	// }

	@JsonApiToOne
	@JsonApiIncludeByDefault
	@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.REFRESH)
	@Fetch(FetchMode.JOIN)
	@JoinColumn(name = "province_id", foreignKey = @ForeignKey(name = "null"))
	public Province getProvince() {
		return province;
	}

	public void setProvince(Province province) {
		this.province = province;
	}

	@Column(name = "city_name")
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public City() {
	}

	@Column(name = "remark")
	public String getRemark() {
		return remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}

}
